from typing import List
from common.enum.strategy_group_enum import StrategyGroup
from common.enum.strategy_type_enum import StrategyType
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_assessment import RiskAssessment
from dto.strategy_stock_day import StrategyStockDay
from service.strategy.base_strategy import BaseStrategy


class ThreeDaysVolumeIncreaseStrategy(BaseStrategy):
    """
    连续3天成交量放大策略，成交量逐日增加
    """

    def analyze(self, trade_info_list: List[StrategyStockDay]) -> RiskAssessment:
        """
        分析过去3天的成交量是否连续放大
        """
        node_point = 0
        description = ""

        # 确保至少有3天的交易数据
        if len(trade_info_list) >= 3:
            is_continuous_increase = True

            # 遍历最近3天的交易数据，确保成交量始终递增
            for i in range(1, 3):
                if trade_info_list[i].vol <= trade_info_list[i - 1].vol:
                    is_continuous_increase = False
                    description = (
                        f"第{i + 1}天的成交量未超过前一天，未满足连续放大条件。"
                    )
                    break

            if is_continuous_increase:
                node_point = 10  # 连续3天成交量放大，得分 +10
                description = "连续3天成交量放大，满足条件。"

        return RiskAssessment(
            stock_code=trade_info_list[0].stock_code,
            description=description,
            config=self.strategyConfig(),
            node_point=node_point,
        )

    def strategyConfig(self) -> StrategyInfoMetadata:
        """
        返回策略的配置
        """
        return StrategyInfoMetadata(
            strategy_code="three_days_volume_increase",
            strategy_name="成交量连续放大",
            strategy_group=StrategyGroup.ATTENTION,
            strategy_type=StrategyType.VOLUME,
            analysis_day=3,
            strategy_level=2,
        )
